
package com.leshalv;

import java.io.File;
import javax.swing.event.ListSelectionEvent;

/**
 *
 * @author SanLi
 */
public class DelClass extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8144021919130192613L;

	/**
	 * Creates new form DelClass
	 */
	public DelClass() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings({ "unchecked", "rawtypes", "serial" })
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jScrollPane1 = new javax.swing.JScrollPane();
		jList1 = new javax.swing.JList();
		btnDel = new javax.swing.JButton();
		btnCnncel = new javax.swing.JButton();
		jSeparator1 = new javax.swing.JSeparator();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setMaximumSize(new java.awt.Dimension(264, 488));
		setResizable(false);
		jList1.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
		jList1.setModel(new javax.swing.AbstractListModel() {
			String[] strings = load();

			public int getSize() {
				return strings.length;
			}

			public Object getElementAt(int i) {
				return strings[i];
			}
		});
		jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
			public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
				lisClassValueChanged(evt);
			}

		});
		jScrollPane1.setViewportView(jList1);

		btnDel.setText("删除");
		btnDel.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnDelActionPerformed(evt);
			}
		});

		btnCnncel.setText("取消");
		btnCnncel.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnCnncelActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap()
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addComponent(jSeparator1)
								.addGroup(layout.createSequentialGroup().addComponent(btnDel)
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 130,
												Short.MAX_VALUE)
										.addComponent(btnCnncel)))
						.addContainerGap())
				.addComponent(jScrollPane1));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 437,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(2, 2, 2)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(btnDel).addComponent(btnCnncel))
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

		pack();
		setLocationRelativeTo(null);
	}// </editor-fold>

	/**
	 * 窗口加载时将Load文件夹下的所有文件夹名称添加进去
	 */
	@SuppressWarnings("finally")
	public String[] load() {
		@SuppressWarnings("unused")
		String name = "";
		String fileName[] = null;
		File file = null;
		File loadFile = null;
		try {
			file = new File("RollCallSystem\\Original");
			loadFile = new File("RollCallSystem\\Load");
			if (file.exists() && loadFile.exists()) {

				fileName = file.list();
				for (int i = 0; i < fileName.length; i++) {
					name += fileName[i] + '\n';
				}
			} else {
				file.mkdirs();
				loadFile.mkdirs();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			return fileName;
		}

	}

	/**
	 * 列表选中事件
	 * 
	 * @param evt
	 */
	private void lisClassValueChanged(ListSelectionEvent evt) {
		// TODO Auto-generated method stub

		@SuppressWarnings("unused")
		String className = (String) jList1.getSelectedValue();

	}

	/**
	 * 刷新列表
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void flush() {
		load();
		jList1.setModel(new javax.swing.AbstractListModel() {
			private static final long serialVersionUID = 4991328138687045452L;
			String[] strings = load();

			public int getSize() {
				return strings.length;
			}

			public Object getElementAt(int i) {
				return strings[i];
			}
		});
		jScrollPane1.setViewportView(jList1);
	}

	/**
	 * 删除
	 * 
	 * @param evt
	 */
	private void btnDelActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		String className = (String) jList1.getSelectedValue();
		if (className != null) {
			new File("RollCallSystem\\Original\\" + className + "\\Name.txt").delete();
			new File("RollCallSystem\\Load\\" + className + "\\Name.txt").delete();
			new File("RollCallSystem\\Original\\" + className).delete();
			new File("RollCallSystem\\Load\\" + className).delete();

		}
		flush();
	}

	/**
	 * 取消
	 * 
	 * @param evt
	 */
	private void btnCnncelActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		this.setVisible(false);
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {

		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(DelClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(DelClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(DelClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(DelClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new DelClass().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify
	private javax.swing.JButton btnCnncel;
	private javax.swing.JButton btnDel;
	@SuppressWarnings("rawtypes")
	private javax.swing.JList jList1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JSeparator jSeparator1;
	// End of variables declaration
}
